Conditions | 5 |
Total Lines | 35 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | export = replaceMultiplicated |
||
2 | |||
3 | function replaceMultiplicated( |
||
4 | sources: string[], |
||
5 | //TODO `searchValue: string[]` or `replacementMap` |
||
6 | searchValue: string, |
||
7 | replacements: string[] |
||
8 | ) { |
||
9 | const $return: (string|string[])[] = sources.concat() |
||
10 | , {length} = replacements |
||
11 | |||
12 | for (let i = $return.length; i--;) { |
||
13 | const line = sources[i] |
||
14 | if (!line.includes(searchValue)) |
||
15 | continue |
||
16 | |||
17 | const replaced: string[] = new Array(length) |
||
18 | |||
19 | for (let j = length; j--;) { |
||
20 | let next = line |
||
21 | , pre: string |
||
22 | |||
23 | //TODO Change to `.replaceAll` with common polyfill |
||
24 | do { |
||
25 | pre = next |
||
26 | next = pre.replace(searchValue, replacements[j]) |
||
27 | } while(next !== pre) |
||
28 | |||
29 | replaced[j] = next |
||
30 | } |
||
31 | |||
32 | $return[i] = replaced |
||
33 | } |
||
34 | |||
35 | //TODO Set up polyfill for `.flat()` |
||
36 | return $return.flat() |
||
37 | } |